package com.zfast.forge.controller;

import com.github.pagehelper.PageInfo;
import com.zfast.config.mybatis.BaseResult;
import com.zfast.config.valid.Create;
import com.zfast.forge.pojo.dto.MagicType;
import com.zfast.forge.service.MagicTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 技能分类
 *
 * @author zgn
 * @email 
 * @date 2024-02-06 13:48:47
 */
@RestController
@RequestMapping("api/magicType")
@Api(tags = {"技能分类"})
public class MagicTypeController{
    @Resource
    MagicTypeService magicTypeService;

    @PostMapping({"/list"})
    @ApiOperation(value = "技能分类数据列表", httpMethod = "POST", notes = "获取技能分类列表")
    public BaseResult<PageInfo<MagicType>> list(MagicType magicType,
            @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
            @RequestParam(name="pageSize", defaultValue="10") Integer pageSize) {
        BaseResult result=BaseResult.builder()
                .msg("获取技能分类列表成功")
                .data(magicTypeService.pageList(magicType,pageNo,pageSize))
                .build();
        return result;
    }

    @GetMapping({"/get/{id}"})
    @ApiOperation(value = "技能分类数据列表", httpMethod = "GET", notes = "获取单个技能分类记录")
    public BaseResult<MagicType> get(@ApiParam(name = "id", value = "业务对象主键", required = true) @PathVariable String id) {
        BaseResult result=BaseResult.builder()
                .msg("查询技能分类成功")
                .data(magicTypeService.get(id))
                .build();
        return result;
    }

    @PostMapping({"add"})
    @ApiOperation(value = "新增技能分类信息", httpMethod = "POST", notes = "保存技能分类")
    public BaseResult<Integer> add(@RequestBody @Validated(Create.class) MagicType model) {
        BaseResult result=BaseResult.builder()
                .msg("添加技能分类成功")
                .data(magicTypeService.insert(model))
                .build();
        return result;
    }

    @PostMapping({"update"})
    @ApiOperation(value = "更新指定id的 技能分类 信息（更新全部信息）", httpMethod = "POST", notes = "更新指定id的 技能分类 信息（更新全部信息）")
    public BaseResult<Integer> update(@RequestBody @ApiParam(name = "magicType", value = "技能分类业务对象", required = true) MagicType model) {
        BaseResult result=BaseResult.builder()
                .msg("更新技能分类成功")
                .data(magicTypeService.update(model))
                .build();
        return result;
    }

    @GetMapping({"remove/{id}"})
    @ApiOperation(value = "删除技能分类记录", httpMethod = "GET", notes = "删除技能分类记录")
    public BaseResult<Integer> remove(@ApiParam(name = "id", value = "业务主键", required = true) @PathVariable String id) {
        BaseResult result=BaseResult.builder()
                .msg("删除技能分类成功")
                .data(magicTypeService.delete(id))
                .build();
        return result;
    }
}
